\documentclass[11pt]{article}
\usepackage{geometry}
\geometry{letterpaper}
\usepackage[parfill]{parskip}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{epstopdf}
\usepackage{amsmath}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

\title{CMSI 371 Assignment Four}
\author{David Hara and Andrew Forney}
\date{\today}
\begin{document}
\maketitle
\begin{center}
\emph{Find the source code at:} \\ http://code.google.com/p/lmu-cmsi-forney/source/browse/
\vspace{250px}
\end{center}
\textbf{Bonus:} \\
\newline Andrew: +2 = [(3/24/11): +1 for incorrect `*' in place of `+'; (4/5/11): +1 for improper vector representation]

\newpage

\textbf{4.1) Commutative nature of Rotation and Scaling:} \\
\newline We can show the commutative nature of these two transformations by performing the matrix multiplication in the general case to illustrate that the same result is achieved. \\
\newline \emph{i) Scaling first, then rotating}

\begin{equation*}
\left[ \begin{array}{ccc}
\cos \theta & -\sin \theta & 0 \\
\sin \theta & \cos \theta & 0 \\ 
0 & 0 & 1 \\
\end{array} \right]
\left[ \begin{array}{ccc}
\Phi & 0 & 0 \\
0 & \Phi & 0 \\ 
0 & 0 & 1 \\
\end{array} \right]
\left[ \begin{array}{ccc}
x \\
y \\ 
1 \\
\end{array} \right]
=
\left[ \begin{array}{ccc}
\cos \theta & -\sin \theta & 0 \\
\sin \theta & \cos \theta & 0 \\ 
0 & 0 & 1 \\
\end{array} \right]
\left[ \begin{array}{ccc}
x \Phi \\
y \Phi \\ 
1 \\
\end{array} \right]
=
\end{equation*}

\begin{equation}
\left[ \begin{array}{ccc}
x \Phi \cos \theta - y \Phi \sin \theta + 0 \\
x \Phi \sin \theta + y \Phi \cos \theta + 0 \\ 
0 + 0 + 1 \\
\end{array} \right] \\
\end{equation}

\emph{ii) Rotating first, then scaling}

\begin{equation*}
\left[ \begin{array}{ccc}
\Phi & 0 & 0 \\
0 & \Phi & 0 \\ 
0 & 0 & 1 \\
\end{array} \right]
\left[ \begin{array}{ccc}
\cos \theta & -\sin \theta & 0 \\
\sin \theta & \cos \theta & 0 \\ 
0 & 0 & 1 \\
\end{array} \right]
\left[ \begin{array}{ccc}
x \\
y \\ 
1 \\
\end{array} \right]
=
\left[ \begin{array}{ccc}
x \cos \theta -y \sin \theta + 0 \\
x \sin \theta + y \cos \theta + 0 \\ 
0 + 0 + 1 \\
\end{array} \right]
\left[ \begin{array}{ccc}
\Phi & 0 & 0 \\
0 & \Phi & 0 \\ 
0 & 0 & 1 \\
\end{array} \right]
=
\end{equation*}

\begin{equation}
\left[ \begin{array}{ccc}
x \Phi \cos \theta - y \Phi \sin \theta + 0 \\
x \Phi \sin \theta + y \Phi \cos \theta + 0 \\ 
0 + 0 + 1 \\
\end{array} \right] \\
\end{equation}

Observe that (1) and (2) are the same result, meaning that the transformations are commutative, simplifying to: \\
\begin{equation}
\left[ \begin{array}{ccc}
x \Phi \cos \theta - y \Phi \sin \theta \\
x \Phi \sin \theta + y \Phi \cos \theta \\ 
1 \\
\end{array} \right] \\
\end{equation}


\newpage
\textbf{4.13) Matrix for glRotate} \\
\newline The abstract method by which glRotate operates is a sequence of rotations resulting in the target axis of rotation aligned with the z-axis. The rotation, specified in glRotate by the first argument of an angle (we'll call this $\theta$), then takes place, and then the axis is restored to its original form in three-space. \\
\newline We can accomplish this in a series of rotation matrix multiplications, in which we perform the following: rotate $\phi_{x}$ degrees about the x axis, rotate $\phi_{y}$ degrees about the y axis, rotate $\theta$ degrees about the z axis, then reverse the first two rotations via $-\phi_{y}$ about the y followed by $-\phi_{x}$ about the x axes.\\
\newline Thus, our final result will be of the form: \\ R = $R_{x}(\phi_{x}) \cdot R_{y}(\phi_{y}) \cdot R_{z}(\theta) \cdot R_{y}(-\phi_{y}) \cdot R_{x}(-\phi_{x})$ \\
\newline The final result should look like the following matrix where $c = \cos(\theta), s = \sin(\theta),\\ ||x, y, z|| = 1$: \\
\begin{center}\includegraphics[scale=0.65]{manpages.png} \end{center}
Our own efforts to derive this target landed somewhat close, but failed to simplify to exactly the correct target. The following represents the Mathematica matrix definitions: \\
\begin{center} \includegraphics[scale=0.6]{matrixderivation.png} \end{center}
This evaluates to: \\
\includegraphics[scale=0.5]{matrixresult.png}


\newpage
\textbf{P64) Triangular wedge extrusion} \\
\newline We can perform the required transformation using a composition of four individual ones: \\
\newline \emph{1) Rotate -90 degrees about the y axis:} We are given that the figure will be flushed against the positive z axis, so the first step is to ensure that we can get an edge on the z axis, even if it's not the right edge--we'll deal with that shortly. \\
\newline \emph{2) Translate by -1 unit in the x direction:} Our figure is currently on the wrong side of the positive z axis, so we'll translate it onto the correct side, with the correct edge now flushed against the positive z axis. \\
\newline \emph{3) Shear by 0.5 xy:} Currently, we have an isosceles triangle, but we need it to be right. As such, we'll shear it 0.5 units in the xy so that the whole side is now intersecting with the positive z axis vertical plane. \\
\newline \emph{4) Scale by 10 / 1.5 in the z direction:} The last thing for us to do is to expand the prism along the positive z axis such that it is 10 units along. Because it is already 1.5 units along the positive z, we'll simply scale by 10 / 1.5. \\
\newline As such, we have a transformation composition of: \\

\begin{equation*}
S_{1, 1, \frac{10}{1.5}} \hspace{8px} \circ \hspace{8px} H_{0.5}^{xy} \hspace{8px} \circ \hspace{8px} T_{-1, 0, 0} \hspace{8px} \circ \hspace{8px} R_{-90}^{y}
\end{equation*}


\newpage
\textbf{5.3) Polar look-at matrix representation} \\
\newline Observe what is happening in this problem from the following illustration:
\begin{center} \includegraphics{CMSI371-HW4-Problem5_3.png} \end{center}
Here, we represent our satellite in three-space by its (x, y, z) coordinate, with its focus upon Earth, at the origin (0, 0, 0). Our goal, however, is to change this representation, and the matrix multiplication of a satellite ``look at" function unto Earth, into the polar coordinate system. To do so, let us represent the angle from the positive x axis as $\theta$ and the angle from the positive y as $\phi$. \\
\newline This allows us to make the following conversions to polar coordinates:

\begin{math}
x = R \cdot \sin \theta \cdot \cos \phi \\
y = R \cdot \cos \theta \\
z = R \cdot \sin \theta \cdot \cos \theta
\end{math}

Now that we have the satellite's coordinates in polar form, we can construct the vector, $F$, that connects the satellite and the view focus. Since the focus is on the origin, we simply get: \\
\newline $F = \hspace{5px} < -R \cdot \sin \theta \cdot \cos \phi,\hspace{5px} -R \cdot \cos \theta,\hspace{5px} -R \cdot \sin \theta \cdot \sin \phi>$

Now, let's normalize $F$ by dividing by its magnitude. We'll call this vector, unimaginatively, $f$. \\

$f \hspace{5px} = \hspace{5px} \frac{F}{||F||} \hspace{5px} = \hspace{5px} \frac{F}{|R| \cdot \sqrt{|\sin \theta \cdot \sin \phi|^{2} + |\sin \theta \cdot \cos \phi|^{2} + |\cos \theta|^{2}}}$ \\

Next, we'll define the up vector normalized on the positive y axis, calling it UP: \\

UP \hspace{5px} $= \hspace{5px} <0, 1, 0>$ \\

Finally, we'll define our remaining transformation elements that are employed in the matrix: \\

$s \hspace{5px} = \hspace{5px} f \hspace{5px} \times$ UP \\
$u \hspace{5px} = \hspace{5px} s \hspace{5px} \times \hspace{5px} f$ \\

Lastly, we'll compile the transformation into its matrix, $M$. Assume for the vector subscripts that $i, j, k$ represent the $<i, j, k>$ elements of each:

\begin{equation}
M \hspace{5px} = \hspace{5px}
\left[ \begin{array}{cccc}
s_{i} & s_{j} & s_{k} & 0 \\
u_{i} & u_{j} & u_{k} & 0 \\ 
-f_{i} & -f_{j} & -f_{k} & 0 \\
0 & 0 & 0 & 1 \\
\end{array} \right] \\
\end{equation}


\newpage
\textbf{5.8) COP-crossing line projection} \\
\newline Observe what is happening in this problem from the following illustration:
\begin{center} \includegraphics{CMSI371-HW4-Problem5_8.png} \end{center}
We see that the line in question is a segment from $p_{0}$ to $p_{1}$. The issue, however, is that the line crosses the center of projection, effectively inverting its projection on either side onto the near clipping plane, N. Unlike what we might expect, that there is simply a hole at the point of crossing the COP plane, the result is that $p_{0}$ and $p_{1}$ form two infinite rays running in opposite directions along N, $p_{0}$ projecting from $p_{0}'$ to negative infinity and $p_{1}$ projecting from $p_{1}'$ to positive infinity. \\

This effect is the result of each point on either side of the segment's intersection with the COP vertical running to their respective infinities, as the angle of the projection of $p_{0}$ nears $-90^{\circ +}$ and the angle of projection for $p_{1}$ nears $90^{\circ -}$. \\

This accounts for the mathematical logic behind the computation, but in OpenGL, the design takes this peculiarity into account and compensates. Obviously, a representation of two infinite rays from a finite line segment is not a logical or observable phenomenon for the purposes of graphics implementations. As such, when the cross over the COP is detected, the engine displays the line segment $p_{0}'$ to $p_{1}'$


\newpage
\textbf{P20) L-system fractal manipulation} \\
\newline Observe what is happening in this problem from the following illustration:
\begin{center} \includegraphics{CMSI371-HW4-ProblemP_20.png} \end{center}
Here, we take an arbitrary line segment and recurse using the L-system description. Let's define some variables!

For starters, let's determine the length of $x$, the size of the horizontal base of each angled segment. We'll use this to determine the scaling factor. So, using basic trigonometry:

$x\hspace{5px} = \hspace{5px} h \cdot \cos \theta$

\vspace{10px} Next, let's find what the length of each sub-segment is; let's call it $h$. Since the original segment is of arbitrary length, we'll just call it $L = 1$ for 100\% of the space Lastly, we'll define our scaling factor as $r$.

\begin{eqnarray*}
L & = & 2h + 2x \\
 & = & 2h + 2h \cdot \cos \theta \\
 & = & 2h (1 + \cos \theta) \\ \\
h & = & \frac{L}{2(1+\cos \theta)} \\ \\
r & = & \frac{1}{2(1+\cos \theta)} 
\end{eqnarray*}

\newpage Nice, now we just have to determine the the fractal dimension, where we have $N = 4$ subdivisions of the fractal:

\begin{eqnarray*}
D & = & \frac{\ln N}{\ln \frac{1}{r}} \\
 & = & \frac{\ln 4}{\ln [2(1 + \cos \theta)]}
\end{eqnarray*}


\newpage
\textbf{P55) Fractal dimensions and L-system description} \\
\newline Observe what is happening in this problem from the following illustration (one last time):
\begin{center} \includegraphics{CMSI371-HW4-ProblemP_55.png} \end{center}
We have an arbitrary line recursing into $N = 4$ smaller ones. From a visual inspection of the fractal, we can see that this is the case, even after many iterations. We also observe that there are two ``mounds" to the figure, signifying two peaks that turn around at 90 degrees. These give us the following L-system: \\

\begin{center}
\begin{math}
\begin{array}{rl}
Axiom & F \\
Rule & F \rightarrow + F - - F + + F - - F \\
Angle & \frac{\pi}{4}
\end{array}
\end{math}
\end{center}

\vspace{10px} Now, all that's left is to determine the fractal dimension with a little trig. Again, we'll refer to $L$ as the arbitrary length of the segment, $x$ as the hypotenuse length between the two isolateral triangles formed by the subdivisions (happens to just be half of L), $h$ will be the length of any one subdivision, $r$ the scaling factor, and $D$ the fractal dimension:

\begin{eqnarray*}
x & = & \sqrt{2} \cdot h \\ \\
1 & = & 2x \\
 & = & 2 \sqrt{2} \cdot h\\ \\
 h & = & \frac{L}{2 \sqrt{2}} \\ \\
\end{eqnarray*}
\begin{eqnarray*}
 r & = & \frac{1}{2 \sqrt{2}} \\ \\
 D & = & \frac{\ln N}{\ln \frac{1}{r}} \\
  & = & \frac{\ln 4}{\ln (2 \sqrt{2})}
\end{eqnarray*}


\end{document}